<template>
    <div class="box">
        <van-list
        v-if="this.total>0"
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        offset="15"
        @load="onLoad"
        >
            <div class="singer">
                <div class="item" @click="gotoSingerInfo(v.id,v.name,v.picUrl)" v-for="(v, i) in recommend" :key="i">
                    <div class="left">
                        <div class="photo">
                            <img :src="v.picUrl" alt="" />
                        </div>
                        <p class="van-ellipsis">{{ v.name }}</p>
                    </div>
                    <span>+关注</span>
                </div>
            </div>
        </van-list>
    </div>
</template>


<script>
export default {
    props:['type'],
    data(){
        return {
            recommend:[],
            loading: false,
            finished: false,
            list:[],
            num:15,
            total:0,
        }
    },
    methods:{
        gotoSingerInfo(id,name,picUrl){
            this.$router.push({name:'singerinfo',params:{id:id,name:name,picUrl:picUrl}});
        },
        onLoad() {
            // 异步更新数据
            // setTimeout 仅做示例，真实场景中一般为 ajax 请求
            
            setTimeout(() => {
                this.recommend = this.recommend.concat(this.list.splice(0,this.num))
                // 加载状态结束
                this.loading = false;

                // 数据全部加载完成
                if (this.recommend.length >= this.total) {
                    this.finished = true;
                }
            }, 1000);
        },
    },
    mounted(){
        this.$ajax.getSingerList({limit:75,type:this.type,}).then(res=>{
            this.list = res.artists;
            this.total = res.artists.length;
        })
    }
}
</script>


<style lang="scss" scoped>
.singer{
    background: #fff;
    width: 100%;
    .item{
        width: 100%;
        height: 5%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 15px;
        box-sizing: border-box;
        .left{
            width: 40%;
            height: 100%;
            display: flex;
            align-items: center;
            .photo{
                margin-right: 10px;
                width: 50px;
                height: 50px;
                border-radius: 50%;
                overflow: hidden;
                display: flex;
                justify-content: center;
                align-items: center;
                img{
                    width: 130%
                }
            }
        }
    }
    
    p{
        font-size: 14px;
        color: #000;
    }
    span{
        padding: 5px 15px;
        letter-spacing: 5px;
        border: 1px solid #f00;
        color: #f00;
        border-radius: 35px;
    }
}
</style>